﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Taperedballnosedendmillsolid
    {
        public static void _Taperedballnosedendmillsolid(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 3; //放大系数

            double oal = 34.42;
            double lpr = 26.99;
            double lh = 20.31;
            double apmx = 15.93;
            double prfa = 6;
            double dcx = 5.37;
            double bd = 5.49;
            double ls = 8.98;
            double dconms = 5.28;
            double dn = 4.84;
            double fha = 38;

            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 6, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 3, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + dconms / 2.276);
            Vector2 v5 = new Vector2(v3.X + (dconms / 2 - v4.Y), v3.Y + dconms / 2);
            Vector2 v6 = new Vector2(v3.X + ls, v5.Y);
            Vector2 v7 = new Vector2(v6.X + 0.5, v3.Y + dn / 2);
            Vector2 v9 = new Vector2(v2.X - 3 - lh, v3.Y + bd / 2);
            Vector2 v8 = new Vector2(v9.X - 0.35, v7.Y);
            Vector2 v10 = new Vector2(v9.X + lh / 11.038, v3.Y + dcx / 2);
            Vector2 v11 = new Vector2(v10.X, v10.Y * -1);
            Vector2 v12 = new Vector2(v9.X, v9.Y * -1);
            Vector2 v13 = new Vector2(v8.X, v8.Y * -1);
            Vector2 v14 = new Vector2(v7.X, v7.Y * -1);
            Vector2 v15 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v16 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v17 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v18 = new Vector2(v2.X - 3 - lpr, v3.Y);
            Vector2 v19 = new Vector2(v18.X, v18.Y + dconms / 2 + 1);
            Vector2 v20 = new Vector2(v19.X, v19.Y * -1);
            Vector2 v21 = new Vector2(v10.X + lh / 12.773, v10.Y - bd / 27.45);
            Vector2 v22 = fun.Polar(v21, -fha * pi / 180, lh / 4.048);
            Vector2 v23 = new Vector2(v22.X + lh / 7.028, v22.Y - bd / 4.007);
            Vector2 v24 = new Vector2(v21.X - lh / 184.436, v21.Y - bd / 24.95);
            Vector2 v25 = fun.Polar(v24, -fha * pi / 180, lh / 4.768);
            Vector2 v26 = new Vector2(v24.X - lh / 35.017, v24.Y - bd / 4.289);
            Vector2 v27 = new Vector2(v26.X + lh / 36.268, v26.Y - bd / 9.631);
            Vector2 v28 = new Vector2(v27.X + lh / 10.155, v27.Y - bd / 3.431);
            Vector2 v29 = new Vector2(v27.X - lh / 88.304, v27.Y - bd / 15.686);
            Vector2 v30 = new Vector2(v11.X + lh / 25.074, v11.Y + bd / 39.214);
            Vector2 v31 = fun.Polar(v21, -fha*pi / 180, lh / 21.379);
            Vector2 v32 = new Vector2(v31.X + lh / 3.761, v31.Y);
            Vector2 v33 = new Vector2(v32.X + lh / 7.228, v32.Y - bd / 3.453);
            Vector2 v34 = new Vector2(v33.X + lh / 7.996, v33.Y - bd / 3.612);
            Vector2 v36 = new Vector2(v3.X + oal, v3.Y);
            Vector2 v35 = new Vector2(v36.X - lh / 15.992, v36.Y - bd / 3.173);
            Vector2 v37 = new Vector2(v32.X + lh / 3.727, v32.Y - bd / 3.287);
            Vector2 v38 = new Vector2(v32.X + lh / 4.12, v32.Y - bd / 5.779);
            Vector2 v39 = new Vector2(v38.X + lh / 37.611, v38.Y - bd / 11.4375);
            Vector2 v40 = new Vector2(v36.X - lh / 13.723, v36.Y + bd / 3.389);
            Vector2 v53 = new Vector2(v36.X - bd / 1.861, v36.Y + bd / 2.889);
            Vector2 v54 = new Vector2(v53.X + bd / 1.61, v53.Y);
            Vector2 v55 = new Vector2(v53.X, v53.Y - bd / 1.386);
            Vector2 v56 = new Vector2(v54.X, v55.Y);

            Vector2 v41 = new Vector2(v2.X - oal / 2.719, v2.Y - dconms / 0.288);
            Vector2 v43 = new Vector2(v41.X - oal / 3.081, v41.Y);
            Vector2 v44 = new Vector2(v41.X - oal / 7.024, v41.Y + oal / 8.334);
            Vector2 v45 = new Vector2(v44.X, v41.Y - oal / 8.334);
            Vector2 v42 = new Vector2(v41.X - oal / 24.762, v41.Y);
            Vector2 v46 = new Vector2(v42.X - lh / 6.955, v42.Y + bd / 1.573);
            Vector2 v47 = new Vector2(v46.X - lh / 5.065, v46.Y + bd / 12.767);
            Vector2 v48 = new Vector2(v47.X - lh / 14.825, v47.Y - bd / 2.484);
            Vector2 v49 = new Vector2(v48.X + lh / 32.758, v48.Y - bd / 2.484);
            Vector2 v50 = new Vector2(v49.X - lh / 39.058, v49.Y - bd / 2.484);
            Vector2 v52 = new Vector2(v42.X - lh / 6.955, v42.Y - bd / 1.573);
            Vector2 v51 = new Vector2(v52.X - lh / 5.065, v52.Y - bd / 12.767);
            Vector2 v57 = new Vector2(v42.X - lh / 1.907, v42.Y + lh / 3.193);
            Vector2 v58 = new Vector2(v57.X + lh / 1.101, v57.Y);
            Vector2 v59 = new Vector2(v58.X, v58.Y - lh / 1.208);
            Vector2 v60 = new Vector2(v57.X, v59.Y);
            Vector2 a1 = new Vector2(v42.X, v52.Y);
            Vector2 a2 = new Vector2(v42.X, v42.Y - oal / 4.924);

            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v21));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            fun.PolyFill(dxf, line2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v8));
            line3.Vertexes.Add(new LwPolylineVertex(v9));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v13));
            line4.Vertexes.Add(new LwPolylineVertex(v8));
            line4.Vertexes.Add(new LwPolylineVertex(v9));
            line4.Vertexes.Add(new LwPolylineVertex(v12));
            line4.Vertexes.Add(new LwPolylineVertex(v13));
            line4.Vertexes.Add(new LwPolylineVertex(v14));
            line4.Vertexes.Add(new LwPolylineVertex(v7));
            line4.Vertexes.Add(new LwPolylineVertex(v8));
            fun.PolyFill(dxf, line4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v6));
            line5.Vertexes.Add(new LwPolylineVertex(v15));
            line5.Vertexes.Add(new LwPolylineVertex(v16));
            line5.Vertexes.Add(new LwPolylineVertex(v5));
            line5.Vertexes.Add(new LwPolylineVertex(v6));
            line5.Vertexes.Add(new LwPolylineVertex(v7));
            line5.Vertexes.Add(new LwPolylineVertex(v14));
            line5.Vertexes.Add(new LwPolylineVertex(v15));
            fun.PolyFill(dxf, line5, 0.1, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v5));
            line6.Vertexes.Add(new LwPolylineVertex(v4));
            line6.Vertexes.Add(new LwPolylineVertex(v17));
            line6.Vertexes.Add(new LwPolylineVertex(v16));
            fun.PolyFill(dxf, line6, 0.1, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v22));
            line7.Vertexes.Add(new LwPolylineVertex(v21));
            line7.Vertexes.Add(new LwPolylineVertex(v24));
            line7.Vertexes.Add(new LwPolylineVertex(v25));
            line7.Vertexes.Add(new LwPolylineVertex(v23));
            line7.Vertexes[3].Bulge = Math.Tan(28 * pi / 180 / 4);
            fun.PolyFill(dxf, line7, 0.1, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v27));
            line8.Vertexes.Add(new LwPolylineVertex(v29));
            line8.Vertexes.Add(new LwPolylineVertex(v30));
            line8.Vertexes[0].Bulge = Math.Tan(35 * pi / 180 / 4);
            fun.PolyFill(dxf, line8, 0.1, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v24));
            line9.Vertexes.Add(new LwPolylineVertex(v26));
            line9.Vertexes[0].Bulge = Math.Tan(121 * pi / 180 / 4);
            fun.PolyFill(dxf, line9, 0.1, contour);

            LwPolyline line10 = new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v28));
            line10.Vertexes.Add(new LwPolylineVertex(v23));
            line10.Vertexes[0].Bulge = Math.Tan(58 * pi / 180 / 4);
            fun.PolyFill(dxf, line10, 0.1, contour);

            Arc c1 = fun.DrawArc3(v11, v30, v28);
            fun.drawBArc(dxf, c1, 0.1, contour);

            Arc c2 = fun.DrawArc3(v22, v23, v34);
            fun.drawBArc(dxf, c2, 0.1, contour);

            Arc c3 = fun.DrawArc3(v33, v32, v31);
            fun.drawBArc(dxf, c3, 0.1, contour);

            Arc c4 = fun.DrawArc3(v33, v34, v35);
            fun.drawBArc(dxf, c4, 0.1, contour);

            Arc c5 = fun.DrawArc3(v26, v27, v28);
            fun.drawBArc(dxf, c5, 0.1, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v32));
            line11.Vertexes.Add(new LwPolylineVertex(v37));
            line11.Vertexes.Add(new LwPolylineVertex(v35));
            line11.Vertexes[0].Bulge = Math.Tan(-57 * pi / 180 / 4);
            line11.Vertexes[1].Bulge = Math.Tan(41 * pi / 180 / 4);
            fun.PolyFill(dxf, line11, 0.1, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v39));
            line12.Vertexes.Add(new LwPolylineVertex(v35));
            line12.Vertexes[0].Bulge = Math.Tan(33 * pi / 180 / 4);
            fun.PolyFill(dxf, line12, 0.1, contour);

            LwPolyline line13 = new LwPolyline();
            line13.Vertexes.Add(new LwPolylineVertex(v40));
            line13.Vertexes.Add(new LwPolylineVertex(v38));
            line13.Vertexes[0].Bulge = Math.Tan(25 * pi / 180 / 4);
            fun.PolyFill(dxf, line13, 0.1, contour);

            Arc c6 = fun.DrawArc3(v39, v38, v32);
            fun.drawBArc(dxf, c6, 0.1, contour);

            Arc c7 = fun.DrawArc3(v35, v36, v40);
            fun.drawBArc(dxf, c7, 0.1, contour);

            Line line17 = new Line(v53, v54);
            line17.Layer = refin;
            line17.Linetype = Linetype.Dashed;
            line17.LinetypeScale = 5;
            dxf.AddEntity(line17);

            Line line18 = new Line(v53, v55);
            line18.Layer = refin;
            line18.Linetype = Linetype.Dashed;
            line18.LinetypeScale = 5;
            dxf.AddEntity(line18);

            Line line19 = new Line(v55, v56);
            line19.Layer = refin;
            line19.Linetype = Linetype.Dashed;
            line19.LinetypeScale = 5;
            dxf.AddEntity(line19);

            Line line20 = new Line(v54, v56);
            line20.Layer = refin;
            line20.Linetype = Linetype.Dashed;
            line20.LinetypeScale = 5;
            dxf.AddEntity(line20);

            Line line25 = new Line(v10, v40);
            line25.Layer = centre;
            line25.Linetype = Linetype.DashDot;
            line25.LinetypeScale = 3;
            dxf.AddEntity(line25);

            Line line26 = new Line(v11, v35);
            line26.Layer = centre;
            line26.Linetype = Linetype.DashDot;
            line26.LinetypeScale = 3;
            dxf.AddEntity(line26);

            //2
            Line line14 = new Line(v41, v43);
            line14.Layer = centre;
            line14.Linetype = Linetype.DashDot;
            line14.LinetypeScale = 3;
            dxf.AddEntity(line14);

            Line line15 = new Line(v44, v45);
            line15.Layer = centre;
            line15.Linetype = Linetype.DashDot;
            line15.LinetypeScale = 3;
            dxf.AddEntity(line15);

            LwPolyline line16 = new LwPolyline();
            line16.Vertexes.Add(new LwPolylineVertex(v46));
            line16.Vertexes.Add(new LwPolylineVertex(v47));
            line16.Vertexes.Add(new LwPolylineVertex(v48));
            line16.Vertexes.Add(new LwPolylineVertex(v49));
            line16.Vertexes.Add(new LwPolylineVertex(v50));
            line16.Vertexes.Add(new LwPolylineVertex(v51));
            line16.Vertexes.Add(new LwPolylineVertex(v52));
            fun.PolyFill(dxf, line16, 0.1, contour);

            Arc c8 = fun.DrawArc3(v52, v42, v46);
            fun.drawBArc(dxf, c8, 0.1, contour);

            Line line21 = new Line(v57, v58);
            line21.Layer = refin;
            line21.Linetype = Linetype.Dashed;
            line21.LinetypeScale = 5;
            dxf.AddEntity(line21);

            Line line22 = new Line(v57, v60);
            line22.Layer = refin;
            line22.Linetype = Linetype.Dashed;
            line22.LinetypeScale = 5;
            dxf.AddEntity(line22);

            Line line23 = new Line(v59, v58);
            line23.Layer = refin;
            line23.Linetype = Linetype.Dashed;
            line23.LinetypeScale = 5;
            dxf.AddEntity(line23);

            Line line24 = new Line(v59, v60);
            line24.Layer = refin;
            line24.Linetype = Linetype.Dashed;
            line24.LinetypeScale = 5;
            dxf.AddEntity(line24);

            LwPolyline line27 = new LwPolyline();
            line27.Vertexes.Add(new LwPolylineVertex(v42));
            line27.Vertexes.Add(new LwPolylineVertex(a2));
            fun.PolyFill(dxf, line27, 0.1, dimensioning);

            fun.drawcircle(dxf, a1, 1, 0.1, dimensioning);


            //坐标系
            fun.Axis(dxf, v36, -90, 180, "", "", "CIP", 0.2, 2, 0);

            fun.Axis(dxf, v18, -90, 180, "", "", "MCS", 0.2, 2, 0);

            fun.Axis(dxf, v3, -90, 180, "", "", "PCS", 0.2, 2, 0);

            fun.Axis(dxf, v42, -90, 180, "", "", "CIP", 0.2, 2, 0);

            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;



            fun.dimrot1(dxf, v36, v4, 0, oal / 2, 1, height, arrowsize, exline, "OAL,LF", "", "");

            fun.dimrot1(dxf, v19, v36, 0, oal / 3, 1, height, arrowsize, exline, "LPR,LTA", "", "");

            fun.dimrot1(dxf, v9, v36, 0, oal / 4, 1, height, arrowsize, exline, "LH", "", "");

            fun.dimrot1(dxf, v31, v36, 0, oal / 6, 1, height, arrowsize, exline, "APMX", "", "");

            fun.dimrot1(dxf, v5, v16, 90, dconms, 1, height, arrowsize, exline, "DCONMS", "", "");

            fun.dimrot1(dxf, v7, v14, -90, dconms, 1, height, arrowsize, exline, "DN", "", "");

            fun.dimrot1(dxf, v17, v15, 180, oal / 6, 1, height, arrowsize, exline, "LS", "", "");

            fun.dimrot1(dxf, v9, v12, -90, oal, 1, height, arrowsize, exline, "BD", "", "");

            fun.dimrot1(dxf, v10, v11, -90, oal * 3 / 4 , 1, height, arrowsize, exline, "DCX", "", "");

            fun.dimrot1(dxf, v46, v52, -90, bd * 3 / 2, 1, height, arrowsize, exline, "DC", "", "");

            fun.jdbz2(dxf, new Line(v40, fun.Polar(v40, (180 - prfa / 2) * pi / 180, 0.1)), new Line(v35, fun.Polar(v35, (prfa / 2 - 180) * pi / 180, 0.1)), oal + apmx / 2, height, arrowsize, exline, "PRFA", "", "");

            fun.jdbz2(dxf, new Line(v22, fun.Polar(v22, -fha  * pi / 180, 0.1)), new Line(v22, fun.Polar(v22, 0 * pi / 180, 0.1)), lh / 2, height, arrowsize, exline, "FHA", "", "");

            fun.jt(dxf, new Vector2(v2.X + oal / 3.988, v2.Y + dconms / 0.258), -90, 9, height, "FDP");

            fun.jt(dxf, new Vector2(v6.X - ls / 2, v6.Y), 100, 9, height, "CCMS");

            fun.jt(dxf, a2, 180, 9, height, "LF");

            fun.jt(dxf, v42, 45, 9, height, "RE");

            fun.text1(dxf, new Vector2(a1.X + oal / 40.023, a1.Y - oal / 9.723), 90, "CRP");


            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
} 